// created by noellynch
// Apr 29, 2008

package com.sceneworker.util.xml;

import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Hashtable;

/**
 * Base tag just contains an attribute parse utility method.<br /><br />
 * <b>NOTE : </b> any sub class that wishes to read a tags attributes <b>MUST</b> define methods that are composed of<br /><br />
 * 
 * kXMLAttributeSetMethodPrefix + &lt;attribute's name&gt;<br /><br />
 * 
 * e.g. if the tag is &lt;test id="first" /&gt; the function that will be called for this attribute is
 * 
 * kXMLAttributeSetMethodPrefix + "first" => public	void	attrSet_first
 * 
 *
 * @author noellynch
 *
 */
public final	class BaseTag
{
	final	static	public		String		kXMLAttributeSetMethodPrefix = "attrSet_";	
	
	/**
	 * This calls the xml attributes callbacks of the sub class.
	 * 
	 * @param cl_loader is the object that is managing the parsing
	 * @param cla_attrs is a hash of the attributes
	 * @param cl_this is the object whose properties are to be initialised by the attributes
	 */
	static	public	void
	attributeParse(TagCallBackLoader cl_loader,
			Hashtable<String, String> cla_attrs, Object cl_this) {
		
		Enumeration<String>		lstra_keys = cla_attrs.keys();
		
		while(lstra_keys.hasMoreElements())
		{
			String		lstr_key = lstra_keys.nextElement();
			
			String		lstr_attr = cla_attrs.get(lstr_key);
			
			//ThruuGlobals.logInfo(BaseTag.class, "handleStart", lstr_key + " = " + lstr_attr);
			
			try 
			{
				Method		lcl_temp = cl_this.getClass().getMethod(kXMLAttributeSetMethodPrefix + lstr_key, lstr_attr.getClass());
				
				lcl_temp.invoke(cl_this, lstr_attr);
			} 
			catch (Exception e) 
			{
				e.printStackTrace();
			}
		}
		
	}
}
